import Foundation

public class ListNode {
    public var val: Int
    public var next: ListNode?
    
    public init(_ val: Int) {
        self.val = val
        self.next = nil
    }
}

extension ListNode: CustomDebugStringConvertible, CustomStringConvertible {
    public var description: String {
        var s = "\(val)"
        var p = self
        while p.next != nil {
            p = p.next!
            s = "\(s) -> \(p.val)"
        }
        return s
    }
    
    public var debugDescription: String {
        var s = "\(val)"
        var p = self
        while p.next != nil {
            p = p.next!
            s = "\(s) -> \(p.val)"
        }
        return s
    }
}

